package com.dfbz.springboot_project.service.impl;

import com.dfbz.springboot_project.entity.Privilege;
import com.dfbz.springboot_project.entity.RolePrivilege;
import com.dfbz.springboot_project.mapper.RolePrivilegeMapper;
import com.dfbz.springboot_project.service.RolePrivilegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Map;

@Service
@Transactional
public class RolePrivilegeServiceImpl implements RolePrivilegeService {
    @Autowired
    RolePrivilegeMapper rolePrivilegeMapper;
    @Override
    public void updateSelective(Map<String, Object> params){
        if (params.containsKey("Rid")){
            rolePrivilegeMapper.DeleteByRid((Integer) params.get("Rid"));
        }
        if (params.containsKey("privileges")&&params.get("privileges")!=""){
            rolePrivilegeMapper.InsertSelective((Integer)params.get("Rid"), (ArrayList<Privilege>) params.get("privileges"));
        }
    }
    @Override
    public void deleteByRid(Integer Rid){
        rolePrivilegeMapper.DeleteByRid(Rid);
    }
    @Override
    public void insert(Map<String, Object> params){
        if (params.containsKey("privileges")&&params.get("privileges")!=""){
            Integer rid = (Integer) params.get("Rid");
            rolePrivilegeMapper.InsertSelective(rid, (ArrayList<Privilege>) params.get("privileges"));
        }
    }
}
